﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1.segments.data_type
{
    class TQ
    {
        public CQ Quantity { get; set; }
        public CM_RI Interval { get; set; }
        public StringBuilder Duration { get; set; }
        public TS Start_Date_time { get; set; }
        public TS End_Date_time { get; set; }
        public StringBuilder Priority { get; set; }
        public StringBuilder Condition { get; set; }
        public StringBuilder Text { get; set; }
        public StringBuilder Conjunction { get; set; }
        public StringBuilder Order_Sequencing { get; set; }


        public int fill(string source, int temp)
        {
            int i, x = 0;
            for (i = temp; i < source.Length; i++)
            {
                if (source[i] == '^')
                    x++;
                else if (source[i] == '|')
                {
                    Duration.Capacity = Duration.Length;
                    Priority.Capacity = Priority.Length;
                    Condition.Capacity = Condition.Length;
                    Text.Capacity = Text.Length;
                    Conjunction.Capacity = Conjunction.Length;
                    Order_Sequencing.Capacity = Order_Sequencing.Length;
                    return i;
                }

                else if (x == 0)
                {
                    if (Quantity == null)
                        Quantity = new  CQ();
                    i = Quantity.fill(source, i);
                }
                else if (x == 1)
                {
                    if (Interval == null)
                        Interval = new CM_RI();
                    i = Interval.fill(source, i);
                }
                else if (x == 2)
                {
                    if (Duration == null)
                        Duration = new StringBuilder();
                    Duration.Insert(Duration.Length, source[i]);
                }
                else if (x == 3)
                {
                    if (Start_Date_time == null)
                        Start_Date_time = new TS ();
                    i = Start_Date_time.fill(source, i);
                }
                else if (x == 4)
                {
                    if (End_Date_time == null)
                        End_Date_time = new TS();
                    i = End_Date_time.fill(source, i);
                }                                
                else if (x == 5)
                {
                    if (Priority == null)
                        Priority = new StringBuilder();
                    Priority.Insert(Duration.Length, source[i]);
                }
                 else if (x == 6)
                {
                    if (Condition == null)
                        Condition = new StringBuilder();
                    Condition.Insert(Condition.Length, source[i]);
                }
                 else if (x == 7)
                {
                    if (Text == null)
                        Text = new StringBuilder();
                    Text.Insert(Text.Length, source[i]);
                }
                 else if (x == 8)
                {
                    if (Conjunction == null)
                        Conjunction = new StringBuilder();
                    Conjunction.Insert(Duration.Length, source[i]);
                }
                 else if (x == 9)
                {
                    if (Order_Sequencing == null)
                        Order_Sequencing = new StringBuilder();
                    Order_Sequencing.Insert(Order_Sequencing.Length, source[i]);
                }
            }
            return i;
        }
    }
}
